# -*- coding: utf-8 -*-
# $Id: admin.py 82 2011-11-22 15:24:55Z 4glitch $


from django.conf import settings
from os import path

settings.TEMPLATE_DIRS += (path.join(path.dirname(__file__), 'templates'),)


from models import Event
from django.utils.translation import ugettext_lazy as _

try: # I use custom admin site here ))
    from donjon import admin
except:
    from django.contrib import admin


class EventAdmin(admin.ModelAdmin):
    list_display = ('date', 'time', 'severity_name', 'host',
                    'program', 'color_message')
    list_filter = ('date', 'severity', 'facility', 'host', 'program')
    list_per_page = 40
    search_fields = ['message']
    date_hierarchy = 'date'
    change_list_template = "event_change_list.html"
    
    def color_message(self, obj):
        return '<span class="%(severity)s">%(message)s</span>' % {
            "message": obj.message,
            "severity": obj.severity_name
            }
    color_message.allow_tags = True
    color_message.short_description = _('message')
    
    def has_add_permission(self, request, obj=None):
        return False
    
    ## def queryset(self, request):
    ##     return super(EventAdmin, self).queryset(request
    ##                                             ).filter(severity__lt=7)
    
    class Media:
        css = {"all": ("grdlog/css/severity.css",)}


admin.site.register(Event, EventAdmin)
